package com.gis3c.sys.security.shiro.filter;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
import org.apache.shiro.web.servlet.ShiroHttpServletResponse;

public class C3ShiroHttpServletResponse extends ShiroHttpServletResponse {
	public C3ShiroHttpServletResponse(
			HttpServletResponse response,ServletContext context,ShiroHttpServletRequest request){
		super(response,context,request);
	}
	
	@Override
	protected String toEncoded(String url,String sessionId){
		if(url == null || "".equals(url)
				|| sessionId == null || "".equals(sessionId)){
			return null;
		}
		String path = url;
		String queryContent = "";
		String anchor = "";
		int queryIndex = url.indexOf("?");
		
		if(queryIndex >= 0){
			path = url.substring(0,queryIndex);
			queryContent = url.substring(queryIndex);
		}
		int pound = path.indexOf("#");
		if(pound > 0){
			anchor = path.substring(pound);
			path = path.substring(0, pound);
		}
		
		StringBuilder sb = new StringBuilder(path);
		sb.append(anchor);
        sb.append(queryContent);
        
        return (sb.toString());
	}
}
